/*-------------------------------------------------------------------------
 *
 * replorigindesc.c
 *	  复制/logical/origin.c 的 rmgr 描述例程
 *
 * Portions Copyright (c) 2015-2022, PostgreSQL Global Development Group
 *
 *
 * IDENTIFICATION
 *	  src/backend/access/rmgrdesc/replorigindesc.c
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include "replication/origin.h"

void replorigin_desc(StringInfo fc_buf, XLogReaderState *fc_record)
{
	char	   *fc_rec = XLogRecGetData(fc_record);
	uint8		fc_info = XLogRecGetInfo(fc_record) & ~XLR_INFO_MASK;

	switch (fc_info)
	{
		case XLOG_REPLORIGIN_SET:
			{
				xl_replorigin_set *fc_xlrec;

				fc_xlrec = (xl_replorigin_set *) fc_rec;

				appendStringInfo(fc_buf, "set %u; lsn %X/%X; force: %d",
								 fc_xlrec->node_id,
								 LSN_FORMAT_ARGS(fc_xlrec->remote_lsn),
								 fc_xlrec->force);
				break;
			}
		case XLOG_REPLORIGIN_DROP:
			{
				xl_replorigin_drop *fc_xlrec;

				fc_xlrec = (xl_replorigin_drop *) fc_rec;

				appendStringInfo(fc_buf, "drop %u", fc_xlrec->node_id);
				break;
			}
	}
}

const char * replorigin_identify(uint8 fc_info)
{
	switch (fc_info)
	{
		case XLOG_REPLORIGIN_SET:
			return "SET";
		case XLOG_REPLORIGIN_DROP:
			return "DROP";
		default:
			return NULL;
	}
}
